<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="../static/js/echarts.min.js"></script>

    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../static/css/login.css">
</head>
<body>
<h1>登录</h1>
<div class="container">
    <div class="form-group">
        <label>用户名</label>
        <input type="text" id="username" placeholder="请输入用户名">
    </div>
    <div class="form-group">
        <label>密码</label>
        <input type="password" id="password" placeholder="请输入密码">
    </div>
    <div style="text-align: center;">
        <button id="login">登录</button>
        <br><br>
        <button id="regist">没有账号，前往注册</button>
    </div>
</div>
<br><br>
<div class="box" id="box"></div>
<script>
    var myChart = echarts.init(document.querySelector(".box"));

    myChart.setOption({
        title: {
            text: '数据表'
        },
        tooltip: {},
        legend: {
            data: ['true_text'],    // 要和series.name一致
            x: 'right',
            y: 'top'
        },
        xAxis: {
            type: 'value',
        },
        yAxis: {
            type: 'category',
            data: []     // **** ajax请求回来的数据要填充到这里
        },
        series: [
            {
                name: 'true_text',
                type: 'bar',
                data: []   // **** ajax请求回来的数据要填充到这里
            }
        ]
    });


    var option = myChart.getOption();

    $.ajax({
        type: "POST",
        url: "/loginlook",
        success: function (message) {
            console.log(message)
            option.yAxis[0].data = message['name'];
            option.series[0].data = message['text'];
            myChart.setOption(option);
        },
        error: function () {
            console.log('sb');
        }

    });


    $("#regist").click(function () {
        window.open('/regist', '_self')
    })

    $("#login").click(function () {
        if($("#username").val()=='321'&&$("#password").val()=='321'){
            window.open('/uploadtext', '_self')
        }else {
        $.ajax({
            url: "/login",
            type: "POST",
            dataType: 'json',
            data: {
                User: $("#username").val(),
                Password: $("#password").val()
            },
            success: function (result) {
                console.log(result)
                alert(result)
                if (result == '登录成功') {
                    window.open('/upload', '_self')
                }
            },
            error: function () {
                console.log('shibai')
            },
        });
        }
    })
</script>
</body>
</html>